<?php

/**
 * This is the model class for table "tbl_image_tag".
 *
 * The followings are the available columns in table 'tbl_image_tag':
 * @property string $id
 * @property string $image_id
 * @property string $position
 * @property integer $item_id
 * @property string $color
 * @property string $shop_url
 * @property string $brand
 *
 * The followings are the available model relations:
 * @property Item $item
 * @property Image $image
 */
class ImageTag extends CActiveRecord {

    const TAG_LOCKED = 0;
    const TAG_ACTIVE = 1;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return ImageTag the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'tbl_image_tag';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('image_id, position, item_id', 'required'),
            array('item_id', 'numerical', 'integerOnly' => true),
            array('image_id', 'length', 'max' => 20),
            array('position', 'length', 'max' => 100),
            array('color', 'length', 'max' => 30),
            array('shop_url', 'length', 'max' => 200),
            array('brand', 'length', 'max' => 50),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, image_id, position, item_id, color, shop_url, brand', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'item' => array(self::BELONGS_TO, 'Item', 'item_id'),
            'image' => array(self::BELONGS_TO, 'Image', 'image_id'),
            'style' => array(self::HAS_MANY, 'TagStyle', 'tag_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'image_id' => 'Image',
            'position' => 'Position',
            'item_id' => 'Item',
            'color' => 'Color',
            'shop_url' => 'Shop Url',
            'brand' => 'Brand',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('image_id', $this->image_id, true);
        $criteria->compare('position', $this->position, true);
        $criteria->compare('item_id', $this->item_id);
        $criteria->compare('color', $this->color, true);
        $criteria->compare('shop_url', $this->shop_url, true);
        $criteria->compare('brand', $this->brand, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
                ));
    }

}